package com.sessioncookie;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 
 * @classDesc: 功能描述:(获取Session 信息)
 */
@WebServlet("/GetSessionServlet")
public class GetSessionServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// 默认是true 标识如果没有session
		// ，就会创建一个sessi,如果false，如果没有摘到session，就不会创建一个session。
		HttpSession session = req.getSession(false);
		if (session != null) {
			String userName = (String) session.getAttribute("userName");
			System.out.println("GetSessionServlet----username:" + userName);
			System.out.println("sessionId:" + session.getId());
		}else{
			System.out.println("没有找到任何结果...");
		}

	}

}